package cn.jiyun.controller;
//import cn.jiyun.common.AutoLogs;
import cn.jiyun.common.config.Result;
import cn.jiyun.entity.Sblx;
import cn.jiyun.service.ISblxService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-10-27
 */
@RestController
@RequestMapping("/sblx")
@CrossOrigin //允许跨域
public class SblxController {

    @Autowired
    private ISblxService sblxService;

    @RequestMapping("/findPage")
    public Result findPage(Integer pageNum, Integer pageSize, @RequestBody Sblx sblx){
        Page page=sblxService.findPage(pageNum,pageSize,sblx);
        return Result.ok(page);
    }

    @RequestMapping("/findById")
    public Result findById(Integer id){
        Sblx sblx=sblxService.getById(id);
        return Result.ok(sblx);
    }

    @RequestMapping("/add")
//    @AutoLogs(value = "设备联系添加操作", loggingtype  = 0)
    public Result add(@RequestBody Sblx sblx){
        if (sblx.getId()==null){
            sblx.setCtime(LocalDateTime.now());
            sblxService.save(sblx);
            return Result.ok("添加成功！");
        }else{
            sblxService.updateById(sblx);
            return Result.ok("修改成功！");
        }
    }

    @RequestMapping("/zhuangtai")
//    @AutoLogs(value = "设备联系更新操作", loggingtype  = 0)
    public Result zhuangtai(Integer id,Integer status){
        Sblx sblx = new Sblx().setId(id).setStatus(status);
        sblxService.updateById(sblx);
        if (status==1){
            return Result.ok("启用成功！");
        }
        return Result.ok("禁用成功！");
    }

    @RequestMapping("/deleteById")
//    @AutoLogs(value = "设备联系删除操作", loggingtype  = 0)
    public Result deleteById(Integer id){
        sblxService.removeById(id);
        return Result.ok("删除成功！");
    }

}
